package leetcode_700;

/**
 *@author 周杨
 *DesignCircularQueue_622 构造循环队列
 *describe:AC 4%
 *2018年9月20日 上午9:51:19
 */
public class DesignCircularQueue_622 {
	int queue[];
	int front;
	int rear;
	int k;
	int size;
	
	 /** Initialize your data structure here. Set the size of the queue to be k. */
    public DesignCircularQueue_622(int k) {
        this.queue=new int[k+1];
        this.front=0;
        this.rear=0;
        this.k=k;
        this.size=0;
    }
    
    /** Insert an element into the circular queue. Return true if the operation is successful. */
    public boolean enQueue(int value) {
        if(this.size==k)
        	return false;
        rear=(rear+1)%k;
        this.queue[rear]=value;
        size++;
        return true;
    }
    
    /** Delete an element from the circular queue. Return true if the operation is successful. */
    public boolean deQueue() {
        if(this.size==0)
        	return false;
        front=(front+1)%k;
        this.size--;
        return true;
    }
    
    /** Get the front item from the queue. */
    public int Front() {
        if(this.size==0)
        	return -1;
        return this.queue[front];
    }
    
    /** Get the last item from the queue. */
    public int Rear() {
        if(this.size==0)
        	return -1;
        return this.queue[rear];
    }
    
    /** Checks whether the circular queue is empty or not. */
    public boolean isEmpty() {
        return this.size==0;
    }
    
    /** Checks whether the circular queue is full or not. */
    public boolean isFull() {
        return this.size==k;
    }
}
